library(lme4)
library(brms)

## Likelihood Models with crossed random effects
## da_id is dissemination area census id

lmer_social_cohesion <- lmer(
  social_cohesion ~ community_perception + objective_pct_vm_DA + (1 | pairidx) + (1 | da_id),
  data = analysisdat
)

## Bayesian model with two random intercepts
## with student_t(3,0,2.5) default priors.
## Slopes have flat priors.
## The brm function uses the Stan language for MCMC sampling.

blmer_social_cohesion <- brm(
  social_cohesion ~ community_perception + objective_pct_vm_DA + (1 | pairidx) + (1 | da_id),
  data = analysisdat,
  chains = 4, iter = 2000, cores = 4,
  control = list(adapt_delta = 0.99, max_treedepth = 20)
)
